$(function() {
    buttenControl();
    selectList('type','1000000002'); // 设备接口类型
    selectList('typeinfo','1000000002'); // 设备接口类型
    $('#tb_ads').bootstrapTable({
        method: 'POST',                      //请求方式（*）
        url:projectPath + "/base/chargers/list",
        contentType: 'application/x-www-form-urlencoded',
        toolbar: '#toolbar',                //工具按钮用哪个容器
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: false,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        search:false,
        queryParams: queryParams,//传递参数（*）
        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                       //初始化加载第一页，默认第一页
        pageSize: 10,                       //每页的记录行数（*）
        pageList: [10,20,50],        //可供选择的每页的行数（*）
        strictSearch: true,
        clickToSelect: true,                //是否启用点击选中行
        uniqueId: "id",
        showColumns: true,                  //是否显示所有的列
        showRefresh: true,                  //显示刷新按钮
        showToggle: true,
        minimumCountColumns: 2,             //最少允许的列数
        singleSelect:true,
        // height:500,
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        columns: [
            {field: 'check', checkbox: true},
            {field: '', title: '序号', align: 'center', formatter: function (value, row, index) {
                var pageSize=$('#tb_ads').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                var pageNumber=$('#tb_ads').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                return pageSize * (pageNumber - 1) + index + 1;    //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
            }},
            {field: 'uuid', title: '主键', align: 'center', visible:false},
            {field: 'chargerno', title: '充电枪编号',align: 'center',formatter: function (value, row, index) {
                return '<div style="white-space: nowrap;"><a href="javascript:;" onclick="charge_gun_detail(\''+ row.assetNo +'\',\''+ row.outchargerno +'\',\''+ row.chargerno +'\',\''+ row.type +'\',\''+ row.stationName +'\',\''+ row.stakeName +'\',\''+ row.parkingSpaceName +'\')">' + value + '</a></div>';
            }},
            {field: 'assetNo', title: '枪资产编码',align: 'center',formatter: function (value, row, index) {
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'type', title: '充电设备接口类型',align: 'center',formatter: function (value, row, index) {
                if(value == "1"){
                    value = "家用插座";
                }else if(value == "2"){
                    value = "交流接口插座";
                }else if(value == "3"){
                    value = "交流接口插头";
                }else if(value == "4"){
                    value = "直流接口枪头";
                }else{
                    value = "其他";
                };
                return "<div style=white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'tcumanucode', title: 'TCU厂商编码',align: 'center',formatter: function (value, row, index) {
                if(value == "" || value == null){
                    value = "";
                };
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'stationName', title: '充电站名称',align: 'center',formatter: function (value, row, index) {
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'stakeName', title: '充电桩名称',align: 'center',formatter: function (value, row, index) {
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'parkingSpaceName', title: '停车位名称',align: 'center',formatter: function (value, row, index) {
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
        ],
        responseHandler: function (obj) {
            return {
                total:obj.data.total,
                rows:obj.data.data
            }
        }
    });
    $('#stake_table').bootstrapTable({
        method: 'POST',                      //请求方式（*）
        //url: projectPath+"/base/stakes/listByStation",
        contentType: 'application/x-www-form-urlencoded',
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: false,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        search:false,
        sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                       //初始化加载第一页，默认第一页
        pageSize: 10,                       //每页的记录行数（*）
        pageList: [10, 15,20],        //可供选择的每页的行数（*）
        strictSearch: true,
        clickToSelect: true,                //是否启用点击选中行
        uniqueId: "id",
        showColumns: false,                  //是否显示所有的列
        showRefresh: false,                  //显示刷新按钮
        showToggle: false,
        minimumCountColumns: 12,             //最少允许的列数
        singleSelect:true,
        // height:500,
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        columns: [
            {field: 'check', checkbox: true},
            {field: '', title: '序号', align: 'center', formatter: function (value, row, index) {
                var pageSize=$('#stake_table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                var pageNumber=$('#stake_table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                return pageSize * (pageNumber - 1) + index + 1;    //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
            }},
            {field: 'uuid', title: '主键', align: 'center', visible:false},
            {field: 'stakeno', title: '桩编号',align: 'center',formatter: function (value, row, index) {
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'stakename', title: '桩名称', align: 'center',formatter: function (value, row, index) {
                return '<div style="white-space: nowrap;">'+ value +'</div>';
            }},
            {field: 'staketype', title: '桩类型',align: 'center',formatter: function (value, row, index) {
                if(value == "1"){
                    value = "专用";
                }else if(value == "2") {
                    value = "公用";
                }else{
                    value = "其他";
                };
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'stakestatus', title: '桩状态', align: 'center',formatter: function (value, row, index) {
                if(value == "2"){
                    value = "待运行";
                }else if(value == "3"){
                    value = "运行";
                }else if(value == "8"){
                    value = "维护";
                }else if(value == "11"){
                    value = "退运";
                }else if(value == "10"){
                    value = "停运";
                }else{
                    value = "其他";
                };
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'type', title: '交直流', align: 'center',formatter: function (value, row, index) {
                if(value == "1"){
                    value = "直流充电桩";
                }else if(value == "2"){
                    value = "交流充电桩";
                }else{
                    value = "通用充电桩";
                };
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'isdebugging', title: '是否调试',align: 'center',formatter: function (value, row, index) {
                if(value == "0"){
                    value = "未调试";
                }else{
                    value = "已调试";
                };
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
            {field: 'isthird', title: '是否三方',align: 'center',formatter: function (value, row, index) {
                if(value == "0" || value == "1"){
                    return "<div style='white-space: nowrap;'>否</div>";
                }else{
                    return "<div style='white-space: nowrap;'>是</div>";
                };
            }},
            {field: 'runtime', title: '投运时间',align: 'center',formatter: function (value, row, index) {
                if(value == "" || value == null){
                    value="";
                }else{
                    value = getLocalTime(value);
                }
                return "<div style='white-space: nowrap;'>" + value + "</div>";
            }},
        ],
        responseHandler: function (obj) {
            if(obj.data.data.length == 0){
                layerAlert.warnMessage("当前站没有绑定桩");
                return;
            };
            return obj.data.data;
        }
    });
    // 查询
    $("#btnQuery").click(function(){
        $('#tb_ads').bootstrapTable('refresh', {url: projectPath + "/base/chargers/list",pageNumber:1});
    });
    // 重置
    $("#btnEmpty").click(function () {
        // 清空对象
        $("#chargerNo").val("");
        $("#assetNo").val("");
        $("#type").val("");
    });

    // 充电站名称查询
    $("#btnQueryStation").click(function(){
        $('#station_table').bootstrapTable('refresh', {url: projectPath+"/base/stations/list"});
    });

    // 验证
    formValidator();
});
// 参数
function queryParams() {
    var filterinfo = {};
    if($("#chargerNo").val() != ""){ // 充电枪编号
        filterinfo.chargerNo = $("#chargerNo").val();
    };
    if($("#assetNo").val() != ""){ // 枪资产编码
        filterinfo.assetNo = $("#assetNo").val();
    };
    if($("#type").val() != ""){ // 设备接口类型
        filterinfo.type = $("#type").val();
    };
    filterinfo.offset = (this.pageNumber-1)*this.pageSize;
    filterinfo.limit = this.pageSize;
    return filterinfo;
};

$("#stationClick").on("click",function () {
    formValidator();
    $(".bootstrapValidators").data('bootstrapValidator').destroy();
    $('.bootstrapValidators').data('bootstrapValidator', null);
    var index = layer.open({
        type: 1,
        title: "搜索充电站",
        shadeClose: true,
        shade: 0.3,
        area: ['90%', '100%'],
        skin: 'layui-layer-rims',
        content: $(".station_detail"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['确定','关闭'],
        success:function(){

        },
        yes:function(){
            var uuid = "";
            var p_n = $('#station_table').bootstrapTable('getData');
            if (p_n != null && p_n.length > 0) {
                var len = $('#station_table').bootstrapTable('getData').length;
                for (var i = 0; i < len; i++) {
                    if ($('#station_table').bootstrapTable('getData')[i].check == true) {
                        uuid = $('#station_table').bootstrapTable('getData')[i].uuid;
                        stationname = $('#station_table').bootstrapTable('getData')[i].stationname;
                    };
                };
                if (uuid != '' && uuid != null) {
                    $("#stationUuid").val(stationname);
                    $("#stationUuid").attr("datauuid",uuid);
                } else {
                    layerAlert.errorMessage("您的选择为空");
                }
            };
            $("#stakeUuid").val("").attr("datauuid","");
            $("#spaceuuid").empty();
            layer.close(index);
        },
        btn2:function(){

        },
        cancel:function () {

        }
    });
});
// 枪 新增 修改 站表格列表初始化
$('#station_table').bootstrapTable({
    method: 'POST',                      //请求方式（*）
    url: projectPath+"/base/stations/list",
    contentType: 'application/x-www-form-urlencoded',
    toolbar: '#toolbar',                //工具按钮用哪个容器
    striped: true,                      //是否显示行间隔色
    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
    pagination: true,                   //是否显示分页（*）
    sortable: false,                     //是否启用排序
    sortOrder: "asc",                   //排序方式
    search:false,
    queryParams: queryStationTabParams,//传递参数（*）
    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
    pageNumber: 1,                       //初始化加载第一页，默认第一页
    pageSize: 10,                       //每页的记录行数（*）
    pageList: [10, 15,20],        //可供选择的每页的行数（*）
    strictSearch: true,
    clickToSelect: true,                //是否启用点击选中行
    uniqueId: "id",
    // showColumns: true,                  //是否显示所有的列
    // showRefresh: true,                  //显示刷新按钮
    // showToggle: true,
    minimumCountColumns: 12,             //最少允许的列数
    singleSelect:true,
    paginationPreText: "上一页",
    paginationNextText: "下一页",
    columns: [
        {field: 'check', checkbox: true},
        {field: '', title: '序号', align: 'center', formatter: function (value, row, index) {
            var pageSize=$('#station_table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
            var pageNumber=$('#station_table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
            return pageSize * (pageNumber - 1) + index + 1;    //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
        }},
        {field: 'uuid', title: '主键', align: 'center', visible:false},
        {field: 'stationname', title: '充电站名称',align: 'center',formatter: function (value, row, index) {
            return '<div style="white-space: nowrap;">'+ value +'</div>';
        }},
        {field: 'stationno', title: '站编码',align: 'center',formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'isthird', title: '是否第三方',align: 'center',formatter: function (value, row, index) {
            if(value == "0" || value == "1"){
                return "<div style='white-space: nowrap;'>否</div>";
            }else{
                return "<div style='white-space: nowrap;'>是</div>";
            };
        }},
        {field: 'lat', title: '经纬度',align: 'center',formatter: function (value, row, index) {
            return (row.lat+"/"+row.lng);
        }},
        {field: 'stationtype', title: '站类型',align: 'center',formatter:function(value, row, index){
            if(row.isthird == 0 || row.isthird == 1){
                switch(value){
                    //1高速,2城市公共,3单位内部,4公交,5其他,6出租车，99岸电
                    case 1:
                        value = "高速"
                        break;
                    case 2:
                        value ="城市公共"
                        break;
                    case 3:
                        value ="单位内部"
                        break;
                    case 4:
                        value ="公交"
                        break;
                    case 5:
                        value ="其他"
                        break;
                    case 6:
                        value ="出租车"
                        break;
                    case 99:
                        value ="岸电"
                        break;
                    default:value ="其他"
                }
            } else {
                switch(value){
                    //(1公共,50个人,100公交专用,101环卫专用,102物流专用,103出租车专用,255其他,99岸电)；
                    case 1:
                        value ="公共"
                        break;
                    case 50:
                        value ="个人"
                        break;
                    case 100:
                        value ="公交专用"
                        break;
                    case 101:
                        value ="环卫专用"
                        break;
                    case 102:
                        value ="物流"
                        break;
                    case 103:
                        value ="出租车"
                        break;
                    case 99:
                        value ="岸电"
                        break;
                    default:value ="其他"
                }
            }
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'stationstatus', title: '站状态', align: 'center',formatter: function (value, row, index) {
            if(value == "2"){
                return "<div style='white-space: nowrap;'>待投运</div>";
            }else if(value == "3"){
                return "<div style='white-space: nowrap;'>运行</div>";
            }else if(value == "8"){
                return "<div style='white-space: nowrap;'>维护</div>";
            }else if(value == "10"){
                return "<div style='white-space: nowrap;'>停运</div>";
            }else if(value == "11"){
                return "<div style='white-space: nowrap'>退运</div>";
            }else{
                return "";
            }
        }},
        {field: 'servicecode', title: '内外部', align: 'center',formatter: function (value, row, index) {
            if(row.urposetype==2){
                if(value==1){
                    return "<div style='white-space: nowrap;'>公用-对外开放</div>";
                } else {
                    return "<div style='white-space: nowrap;'>公用-对内开放</div>";
                }
            } else {
                return "<div style='white-space: nowrap;'>专用-不展示</div>";
            }
        }},
        {field: 'provinceName', title: '省份',align: 'center',visible:false,formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'cityName', title: '城市',align: 'center',visible:false,formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'provinceOrgName', title: '省组织机构',align: 'center',formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'cityOrgName', title: '市组织机构', align: 'center',formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'prOrgName', title: '产权单位', align: 'center',formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'managerOrgName', title: '运维单位', align: 'center',formatter: function (value, row, index) {
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'rundate', title: '投运时间', align: 'center',visible:false,formatter: function (value, row, index) {
            if(value == "" || value == null){
                value="";
            }else{
                value = getLocalTime(value);
            };
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }},
        {field: 'createdat', title: '最近更新时间', align: 'center',sortable:true,order:'desc',visible:false,formatter: function (value, row, index) {
            if(row.updatedat != '' && row.updatedat != null){
                value = row.updatedat;
            }
            if(value == "" || value == null){
                value="";
            }else{
                value = getLocalTime(value);
            }
            return "<div style='white-space: nowrap;'>" + value + "</div>";
        }}
    ],
    responseHandler: function (obj) {
        return {
            total:obj.data.total,
            rows:obj.data.data
        }
    }
});
function queryStationTabParams() {
    var filterinfo = {};
    if ($('#stationName').val() != '') {// 充电站名
        filterinfo.name = $("#stationName").val();
    };
    filterinfo.offset = (this.pageNumber-1)*this.pageSize;
    filterinfo.limit = this.pageSize;
    return filterinfo;
};

$("#stakeClick").on("click",function () {
    formValidator();
    $(".bootstrapValidators").data('bootstrapValidator').destroy();
    $('.bootstrapValidators').data('bootstrapValidator', null);
    var stationuuid = $("#stationUuid").attr("datauuid");
    if(stationuuid){
        $('#stake_table').bootstrapTable('refresh', {url:projectPath+"/base/stakes/listByStation?stationuuid="+stationuuid});
    }else if(stationuuid == undefined){
        layerAlert.errorMessage("请先选择充电站!");
        return false;
    };
    var index1 = layer.open({
        type: 1,
        title: "搜索充电桩",
        shadeClose: true,
        shade: 0.3,
        area: ['90%', '100%'],
        skin: 'layui-layer-rims',
        content: $(".stake_detail"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['确定','关闭'],
        success:function(){
        },
        yes:function(){
            var parkingareauuid = "";
            var uuid = "";
            var stakename = "";
            var stakeno = "";
            var p_n = $('#stake_table').bootstrapTable('getData');
            if (p_n != null && p_n.length > 0) {
                var len = $('#stake_table').bootstrapTable('getData').length;
                for (var i = 0; i < len; i++) {
                    if ($('#stake_table').bootstrapTable('getData')[i].check == true) {
                        uuid = $('#stake_table').bootstrapTable('getData')[i].uuid;
                        parkingareauuid = $('#stake_table').bootstrapTable('getData')[i].parkingareauuid;
                        stakename = $('#stake_table').bootstrapTable('getData')[i].stakename;
                        stakeno = $('#stake_table').bootstrapTable('getData')[i].stakeno; // 充电桩编号
                    };
                };
                if (parkingareauuid != '' && parkingareauuid != null) {
                    $("#stakeUuid").val(stakename);
                    $("#stakeUuid").attr("datauuid",uuid);
                    $("#stakeUuid").attr("parkingareauuid",parkingareauuid);
                    // 生成枪 互联互通编号
                    $("#outchargerno").val(stakeno+"001");
                    $("#chargerno").val("0");
                    $("#assetno").val(stakeno+"001");
                    $("#hidstakeno").val(stakeno);
                } else {
                    layerAlert.errorMessage("您的选择为空");
                }
            };
            getParkSpaceList();
            layer.close(index1);
        },
        btn2:function(){

        },
        cancel:function () {

        }
    });
});

// 获取停车位list
function getParkSpaceList () {
    $.ajax({
        url: projectPath + '/base/parking/spaces/listByArea?parkingAreaUuid=' + $("#stakeUuid").attr("parkingareauuid"),
        type: 'POST',
        dataType: 'json',
        success:function (data) {
            var parkspaceList=data.data;
            // 判断当前桩下是否存在停车位
            if(parkspaceList == null || parkspaceList.length == 0){
                layerAlert.errorMessage("当前桩下无停车位,请在停车位列表新建!");
            }else {
                $("#spaceuuid").empty();
                $("#spaceuuid").append("<option value=''>--请选择--</option>");
                $.each(parkspaceList, function (index, item) {
                    if (item.bindedCharger == "0") {
                        $("#spaceuuid").append("<option value='" + item.uuid + "'>" + item.name + "</option>");
                    } else if (item.bindedCharger == "1") {
                        $("#spaceuuid").append("<option value='" + item.uuid + "' title='该停车位已绑定，不可选择！' style='background-color: red;' disabled>" + item.name + "</option>");
                    }
                    ;
                });
            }
        },
        error:function () {
            layerAlert.errorMessage("出错了");
        }
    });
};



//新增
$("#btnAdd").on("click",function(){
    formValidator();
    layer.open({
        type: 1,
        title: "新增充电枪",
        shadeClose: true,
        shade: 0.3,
        area: ['80%', '80%'],
        skin: 'layui-layer-rims',
        content: $(".addGun"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['确定','关闭'],
        yes:function(){
            formValidator();
            var bootstrapValidator = $(".bootstrapValidators").data('bootstrapValidator');
            bootstrapValidator.validate();
            if(!bootstrapValidator.isValid()){
                return;
            };
            var dataParams = {
                assetNo:$("#assetno").val(), //  枪资产编码
                outchargerno:$("#outchargerno").val(), // 互联互通
                chargerno:$("#chargerno").val(), // 充电枪编号
                type:$("#typeinfo").val(), // 设备接口类型
                stationUuid:$("#stationUuid").attr("datauuid"), // 充电站 uuid
                stakeUuid:$("#stakeUuid").attr("datauuid"),// 充电桩 uuid
                spaceuuid:$("#spaceuuid").val(), // 停车位
                stakeNo:$("#hidstakeno").val(),//桩编号
                parkingAreaUuid:$("#stakeUuid").attr("parkingareauuid"), //停车区uuid
            };
            $.ajax({
                url: projectPath + '/base/chargers/add',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(dataParams),
                success:function(data){
                    debugger;
                    if(data.code == "0"){
                        layerAlert.successMessage("新增成功","");
                    }else{
                        layerAlert.errorMessage("新增失败");
                    }
                },
                error:function(){
                    layerAlert.errorMessage("错误");
                }
            });
            // 验证重置与输入框清空
            $(".addGun input,select").val("");
            formValidator();
            $(".bootstrapValidators").data('bootstrapValidator').destroy();
            $('.bootstrapValidators').data('bootstrapValidator', null);

        },
        btn2:function(){
            // 验证重置与输入框清空
            $(".addGun input,select").val("");
            formValidator();
            $(".bootstrapValidators").data('bootstrapValidator').destroy();
            $('.bootstrapValidators').data('bootstrapValidator', null);
        },
        cancel:function(){
            // 验证重置与输入框清空
            $(".addGun input,select").val("");
            formValidator();
            $(".bootstrapValidators").data('bootstrapValidator').destroy();
            $('.bootstrapValidators').data('bootstrapValidator', null);
        }
    });
});
// 修改
$("#btnRevise").on("click",function(){
    formValidator();
    $(".addGun select,input").prop("disabled",false);
    var assetNo = "", outchargerno = "", /*nationalstandard = "",*/ /*tcumanucode = "", */chargerno = "", type = "", stationName = "", stakeName = "", parkingSpaceName = "";
    var p_n = $('#tb_ads').bootstrapTable('getData');
    if (p_n != null && p_n.length > 0) {
        var len = $('#tb_ads').bootstrapTable('getData').length;
        for (var i = 0; i < len; i++) {
            if ($('#tb_ads').bootstrapTable('getData')[i].check == true) {
                ids = $('#tb_ads').bootstrapTable('getData')[i].uuid;
                assetNo = $('#tb_ads').bootstrapTable('getData')[i].assetNo;
                outchargerno = $('#tb_ads').bootstrapTable('getData')[i].outchargerno;
                /* nationalstandard = $('#tb_ads').bootstrapTable('getData')[i].nationalstandard;*/
                // = $('#tb_ads').bootstrapTable('getData')[i].tcumanucode;
                chargerno = $('#tb_ads').bootstrapTable('getData')[i].chargerno;
                type = $('#tb_ads').bootstrapTable('getData')[i].type;
                stationName = $('#tb_ads').bootstrapTable('getData')[i].stationName;
                stakeName = $('#tb_ads').bootstrapTable('getData')[i].stakeName;
                parkingSpaceName = $('#tb_ads').bootstrapTable('getData')[i].parkingSpaceName;

                // 充电站uuid(查询充电桩使用)   停车区uuid(查询停车位使用)    TODO
                stationUuid = $('#tb_ads').bootstrapTable('getData')[i].stationUuid;
                parkingAreaUuid = $('#tb_ads').bootstrapTable('getData')[i].parkingAreaUuid;


            };
        };
        if (ids != '' && ids != null) {
            $("#assetno").val(assetNo);
            $("#outchargerno").val(outchargerno);
            $("#chargerno").val(chargerno);
            $("#typeinfo").val(type);
            $("#stationUuid").val(stationName);
            $("#stationUuid").attr("datauuid",stationUuid); // 新的
            $("#stakeUuid").val(stakeName);
            $("#stakeUuid").attr("parkingareauuid",parkingAreaUuid); // 新的
            $("#spaceuuid").html('<option value="">'+parkingSpaceName+'</option>');
            layer.open({
                type: 1,
                title: "修改充电枪",
                shadeClose: true,
                shade: 0.3,
                area: ['80%', '80%'],
                skin: 'layui-layer-rims',
                content: $(".addGun"),
                closeBtn:1,
                shadeClose:false,
                fixed:false,
                resize:true,
                maxmin:true,
                btn:['确定','关闭'],
                success:function () {
                },
                yes:function(){
                    formValidator();
                    var bootstrapValidator = $(".bootstrapValidators").data('bootstrapValidator');
                    bootstrapValidator.validate();
                    if(!bootstrapValidator.isValid()){
                        return;
                    };
                    var dataParams = {
                        assetNo:$("#assetno").val(), //  枪资产编码
                        outchargerno:$("#outchargerno").val(), // 互联互通
                        chargerno:$("#chargerno").val(), // 充电枪编号
                        type:$("#typeinfo").val(), // 设备接口类型
                        stationUuid:$("#stationUuid").attr("datauuid"), // 充电站 uuid
                        stakeUuid:$("#stakeUuid").attr("datauuid"),// 充电桩 uuid
                        spaceuuid:$("#spaceuuid").val(), // 停车位
                        parkingAreaUuid:$("#stakeUuid").attr("parkingareauuid"), //停车区uuid
                        uuid:ids, // 主键
                    };
                    debugger;
                    $.ajax({
                        url: projectPath + '/base/chargers/update',
                        type: 'POST',
                        dataType: 'json',
                        contentType: 'application/json',
                        data: JSON.stringify(dataParams),
                        success:function(data){
                            debugger;
                            if(data.code == "0"){
                                layerAlert.successMessage("修改成功","");
                            }else{
                                layerAlert.errorMessage("修改失败");
                            }
                        },
                        error:function(){
                            layerAlert.errorMessage("错误");
                        }
                    });
                    $(".addGun input,select").val("");
                    formValidator();
                    $(".bootstrapValidators").data('bootstrapValidator').destroy();
                    $('.bootstrapValidators').data('bootstrapValidator', null);
                },
                btn2:function(){
                    $(".addGun input,select").val("");
                    formValidator();
                    $(".bootstrapValidators").data('bootstrapValidator').destroy();
                    $('.bootstrapValidators').data('bootstrapValidator', null);
                },
                cancel:function(){
                    $(".addGun input,select").val("");
                    formValidator();
                    $(".bootstrapValidators").data('bootstrapValidator').destroy();
                    $('.bootstrapValidators').data('bootstrapValidator', null);
                },
            });
        } else {
            layerAlert.errorMessage("您的选择为空");
        }
    };
});

// 详情查看
function charge_gun_detail(index1,index2,index5,index6,index7,index8,index9){
    $(".addGun select,input").prop("disabled",true);
    layer.open({
        type: 1,
        title: "充电枪详情",
        shadeClose: true,
        shade: 0.3,
        area: ['80%', '80%'],
        skin: 'layui-layer-rims',
        content: $(".addGun"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['关闭'],
        success:function(){
            $("#assetno").val(index1);
            $("#outchargerno").val(index2);
            $("#chargerno").val(index5);
            $("#typeinfo").val(index6);
            $("#stationUuid").val(index7);
            $("#stakeUuid").val(index8);
            $("#spaceuuid").val(index9);
            $("#spaceuuid").html('<option value="">'+ index9 +'</option>');
        },
        btn1:function(){
            $(".addGun select,input").val("");
            $(".addGun select,input").prop("disabled",false);
        },
        cancel:function(){
            $(".addGun select,input").val("");
            $(".addGun select,input").prop("disabled",false);
        }
    });
}



$("#btnDelete").on("click",function(){
    var ids = getSelectedDeleteParams();
    if (ids != '' && ids != null) {
        layerAlert.confirmMessage("确定要删除?",projectPath + "/base/chargers/delete?uuid="+ids, function(data){
            debugger;
            if(data.code == "0"){
                layerAlert.successMessage("操作成功","");
            }else{
                layerAlert.errorMessage("出错了");
            };
        });
    }else{
        layerAlert.errorMessage("您的选择为空");
    }
});
// 导出
$("#btnExport").on("click",function(){
    layer.open({
        type: 1,
        title: "选择导出页数",
        shadeClose: true,
        shade: 0.3,
        move :false,
        area: ['300px', '250px'],
        skin: 'layui-layer-rims',
        content: $(".export_dialog"),
        btn:['确定'],
        closeBtn:1,
        success:function(){
            $('.export_dialog').empty();
            //var endPage=pageCount;
            //var startPage=1;
            var str=[
                '<div class="form-group" style="margin-top:30px;margin-left: 10px;">',
                '<label class="label-width3">起始页:</label><input type="text"  class="form-control" id="start_page" value="1" />',
                '</div>',
                '<div class="form-group" style="margin-top: 10px;margin-left: 10px;">',
                '<label class="label-width3">结束页:</label><input type="text"  class="form-control" id="end_page" value="1000"/>',
                '</div>',
            ].join('');
            $('.export_dialog').append(str);
        },
        close:function(){
            $('.export_dialog').remove(str);
        },
        btn1:function(){
            alert("导出成功");
        }
    });
});

// 新增修改提交验证
function formValidator(){
    $(".bootstrapValidators").bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            //valid: 'glyphicon glyphicon-ok',
            //invalid: 'glyphicon glyphicon-remove',
            //validating: 'glyphicon glyphicon-refresh'
        },
        fields:{
            typeinfo:{
                validators:{
                    notEmpty: {
                        message: '设备接口类型不能为空'
                    },
                },
            },
            stationUuid:{
                validators:{
                    notEmpty:{
                        message:"充电站名称不能为空"
                    },
                }
            },
            stakeUuid:{
                validators:{
                    notEmpty:{
                        message:"充电桩名称不能为空"
                    }
                }
            },
            spaceuuid:{
                validators:{
                    notEmpty:{
                        message:"停车位名称不能为空"
                    }
                }
            }
        }
    });
};


// 下拉框动态获取
function selectList(id,code) {
    $.get(projectPath + '/base/constss/list?code='+code, function (r) {
        var data = r.data;
        var value = '<option value="">--请选择--</option>';
        $(data).each(function(index,r){
            value += '<option value="'+r.constvalue+'">'+r.constname+'</option>';
        })
        $("#" + id).append(value);
    });
};


function buttenControl() {
    var urls = paramUrlByButten();
    if(urls.length>0){
        for (var i in urls){
            if('update' == urls[i]){
                $("#btnRevise").show();
            } else if('insert' == urls[i]){
                $("#btnAdd").show();
            }else if('delete' == urls[i]){
                $("#btnDelete").show()
            }else if('excel' == urls[i]){
                $("#btnExport").show()
            }
        }
    }
}